<?php
class Item
{
	public $ASIN;
	public $link;
	public $title;
	public $image;
	public $description;
	public $score = 1;
	public $tags = array();
	
	public function score($tags)
	{
		foreach($tags as $tag)
		{
			$multiplier = (10 * substr_count($this->title, $tag->word) + substr_count($this->description, $tag->word)) * $tag->score;
			
			if($multiplier > 0)
			{
				$this->tags[] = $tag;
			}
			
			$this->score *= ($multiplier + 1); 
		}
	}
	
	static function compare($a, $b)
	{
		if($a->score == $b->score)
			return 0;
		
		return ($a->score > $b->score) ? -1 : +1;
	}
}
?>
